var i;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var c;
var _decorator = cc._decorator;
var _ccclass = _decorator.ccclass;
var _property = _decorator.property;
var d = _decorator.disallowMultiple;
var _menu = _decorator.menu;
var _executionOrder = _decorator.executionOrder;
!function (e) {
  e[e.NONE = 0] = "NONE";
  e[e.TOGGLE = 1] = "TOGGLE";
  e[e.SWITCH = 2] = "SWITCH";
}(c || (c = {}));
var _def_ListItem = function (e) {
  function _creator() {
    var t = null !== e && e.apply(this, arguments) || this;
    t.icon = null;
    t.title = null;
    t.selectedMode = c.NONE;
    t.selectedFlag = null;
    t.selectedSpriteFrame = null;
    t._unselectedSpriteFrame = null;
    t.adaptiveSize = false;
    t._selected = false;
    t._eventReg = false;
    return t;
  }
  __extends(_creator, e);
  Object.defineProperty(_creator.prototype, "selected", {
    get: function () {
      return this._selected;
    },
    set: function (e) {
      this._selected = e;
      if (this.selectedFlag) {
        switch (this.selectedMode) {
          case c.TOGGLE:
            this.selectedFlag.active = e;
            break;
          case c.SWITCH:
            var t = this.selectedFlag.getComponent(cc.Sprite);
            t && (t.spriteFrame = e ? this.selectedSpriteFrame : this._unselectedSpriteFrame);
        }
      }
    },
    enumerable: false,
    configurable: true
  });
  Object.defineProperty(_creator.prototype, "btnCom", {
    get: function () {
      this._btnCom || (this._btnCom = this.node.getComponent(cc.Button));
      return this._btnCom;
    },
    enumerable: false,
    configurable: true
  });
  _creator.prototype.onLoad = function () {
    if (this.selectedMode == c.SWITCH) {
      var e = this.selectedFlag.getComponent(cc.Sprite);
      this._unselectedSpriteFrame = e.spriteFrame;
    }
  };
  _creator.prototype.onDestroy = function () {
    this.node.off(cc.Node.EventType.SIZE_CHANGED, this._onSizeChange, this);
  };
  _creator.prototype._registerEvent = function () {
    if (!this._eventReg) {
      this.btnCom && this.list.selectedMode > 0 && this.btnCom.clickEvents.unshift(this.createEvt(this, "onClickThis"));
      this.adaptiveSize && this.node.on(cc.Node.EventType.SIZE_CHANGED, this._onSizeChange, this);
      this._eventReg = true;
    }
  };
  _creator.prototype._onSizeChange = function () {
    this.list._onItemAdaptive(this.node);
  };
  _creator.prototype.createEvt = function (e, t, o) {
    undefined === o && (o = null);
    if (e.isValid) {
      e.comName = e.comName || e.name.match(/\<(.*?)\>/g).pop().replace(/\<|>/g, "");
      var n = new cc.Component.EventHandler();
      n.target = o || e.node;
      n.component = e.comName;
      n.handler = t;
      return n;
    }
  };
  _creator.prototype.showAni = function (e, t, o) {
    var n;
    var i = this;
    switch (e) {
      case 0:
        n = cc.tween(i.node).to(.2, {
          scale: .7
        }).by(.3, {
          y: 2 * i.node.height
        });
        break;
      case 1:
        n = cc.tween(i.node).to(.2, {
          scale: .7
        }).by(.3, {
          x: 2 * i.node.width
        });
        break;
      case 2:
        n = cc.tween(i.node).to(.2, {
          scale: .7
        }).by(.3, {
          y: -2 * i.node.height
        });
        break;
      case 3:
        n = cc.tween(i.node).to(.2, {
          scale: .7
        }).by(.3, {
          x: -2 * i.node.width
        });
        break;
      default:
        n = cc.tween(i.node).to(.3, {
          scale: .1
        });
    }
    (t || o) && n.call(function () {
      if (o) {
        i.list._delSingleItem(i.node);
        for (var e = i.list.displayData.length - 1; e >= 0; e--) {
          if (i.list.displayData[e].id == i.listId) {
            i.list.displayData.splice(e, 1);
            break;
          }
        }
      }
      t();
    });
    n.start();
  };
  _creator.prototype.onClickThis = function () {
    this.list.selectedId = this.listId;
  };
  __decorate([_property({
    type: cc.Sprite,
    // tooltip: false
  })], _creator.prototype, "icon", undefined);
  __decorate([_property({
    type: cc.Node,
    // tooltip: false
  })], _creator.prototype, "title", undefined);
  __decorate([_property({
    type: cc.Enum(c),
    // tooltip: false
  })], _creator.prototype, "selectedMode", undefined);
  __decorate([_property({
    type: cc.Node,
    // tooltip: false,
    visible: function () {
      return this.selectedMode > c.NONE;
    }
  })], _creator.prototype, "selectedFlag", undefined);
  __decorate([_property({
    type: cc.SpriteFrame,
    // tooltip: false,
    visible: function () {
      return this.selectedMode == c.SWITCH;
    }
  })], _creator.prototype, "selectedSpriteFrame", undefined);
  __decorate([_property({
    // tooltip: false
  })], _creator.prototype, "adaptiveSize", undefined);
  return __decorate([_ccclass, d(), _menu("UI组件/List Item"), _executionOrder(-5001)], _creator);
}(cc.Component);
exports.default = _def_ListItem;